package com.mspbots.cw.amqp.receivers;

import com.mspbots.cw.amqp.BaseReceiver;
import com.mspbots.cw.amqp.model.ProjectPhase;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Optional;

/**
 * BoardReceiver is com.mspbots.cw.amqp.receivers
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2020/2/24
 */
@Log4j2
@Component
@RequiredArgsConstructor
public class ProjectPhaseReceiver extends BaseReceiver {

    @RabbitListener(queues = "wise.project.phase")
    public void processBoard(ProjectPhase projectPhase) {
        /*Optional<Long> id = this.databaseClient.execute("select id from tenant_project_phase " +
                "where tenant_id =:tenantId and cw_id =:cwId")
                .as(Long.class)
                .bind("tenantId", projectPhase.getTenantId())
                .bind("cwId", projectPhase.getCwId())
                .fetch().one().blockOptional(Duration.ofSeconds(10));
        if (id.isPresent() && id.get() > 0) {
            log.debug("Receiver connect wise tenant id:{},cw id:{},projectPhase update id:{}",
                    projectPhase.getTenantId(), projectPhase.getCwId(), projectPhase.getId());
            projectPhase.setId(id.get());
            projectPhase.setSyncTime(LocalDateTime.now());
            this.databaseClient.update().table(ProjectPhase.class).using(projectPhase).fetch().rowsUpdated().subscribe();
        } else {
            this.databaseClient.insert().into(ProjectPhase.class).using(projectPhase).fetch().rowsUpdated().subscribe();
        }*/
    }

}
